<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/ajax.js"></script>
</head>

<body>

</body>
<script>



    function readText(url) {
        var p = new Promise(function (resolve, reject) {
            $.ajax({
                type: "get",
                url: url,
                // dataType: "text",
                success: function (txt) {
                    resolve(txt);
                }
            })
        })
        return p;
    }

    // readText("../data/1.txt").then(function (txt) {
    //     console.log("已成功", txt);
    //     readText("../data/2.txt").then(function (txt) {
    //         console.log("已成功", txt);
    //         readText("../data/3.txt").then(function (txt) {
    //             console.log("已成功", txt);
    //         }).catch(err => {
    //             throw err;
    //         })
    //     }).catch(err => {
    //         throw err;
    //     })
    // }).catch(err => {
    //     throw err;
    // })


    // T = T1 + T2 + T3
    var str = "";
    readText("../data/1.txt").then(function (txt) {
        console.log("已成功", txt);
        str += txt;
        return readText("../data/2.txt");  // 返回的Promise实例
    }).then(function (txt) {
        console.log("已成功", txt);
        str += txt;
        return readText("../data/3.txt");  // 返回的Promise实例
    }).then(function (txt) {
        console.log("已成功", txt);
        str += txt;
        return str;
    }).then(function (txt) {
        console.log("全部成功", str);
    }).catch(err => {
        throw err;
    })




</script>

</html>